<?php
/* Widget Content */
$slug = pods_url_variable('last');

if (is_user_logged_in()){
  $user_id = get_buzzr_users_pod_id();
  $user = new Pod('users',$user_id);
  $user->page = 1;
  $user->search = false;
  $user_coupon_name = $user->get_field('coupons.name');
  $user_coupon_link = $user->get_field('coupons.associated_deal.camp_link');
  $loggedin_user_slug = $user->get_field('slug');
  
  if($loggedin_user_slug == $slug){
    $edit_profile_link = BUZZR_URL.'/editprofile';
    if(!empty($user_coupon_name)){
?>
      <strong>Your Coupons<br /></strong>
      <a href="<?php echo BUZZR_URL.'/deals/'.$user_coupon_link; ?>"><?php echo $user_coupon_name; ?></a><br /><br />
<?php 
    }
  }
}

$users_pod = new Pod('users',$slug);
$user_pod_created = $users_pod->get_field('created');
$users_wordpress_id = $users_pod->get_field('wp_user.ID');
$users_name = $users_pod->get_field('name');
$user_points_reg = $users_pod->get_field('points.registration');
$user_points_login = $users_pod->get_field('points.login');
$user_points_comments = $users_pod->get_field('points.comments');
$user_points_deals = $users_pod->get_field('points.deals');
$user_points_like_fb = $users_pod->get_field('points.like_fb');
$user_points_feedback = $users_pod->get_field('points.feedback');
$user_points_vote = $users_pod->get_field('points.vote');
$user_points_referral = $users_pod->get_field('points.referral');
$user_points_referral = $users_pod->get_field('points.referral');
$user_paid_affiliate = $users_pod->get_field('paid_affiliate');
if(!empty($user_paid_affiliate)){ $user_referrals = $users_pod->get_field('users_referred'); }


$split_name = explode(' ',$users_name); 

echo '<strong>'.$split_name['0'].'</strong><br /><div class="member_prof_pic">'.get_avatar($users_wordpress_id,100).'</div>
<div class="member_since">Member Since '.buzzr_time_since($user_pod_created).'</div>';

if(empty($user_paid_affiliate)){
echo "<div class='member_points'><strong>Points<br /></strong>";
$total_points = $user_points_reg + $user_points_login + $user_points_comments + $user_points_deals + $user_points_like_fb + $user_points_feedback + $user_points_vote + $user_points_referral;
echo '<font color="red"><b>'.$total_points.' pts.</b></font></div>';
}
else{
echo "<div class='member_points'><strong>Referrals<br /></strong>";
$count_ref = count($user_referrals);
echo '<font color="red"><b>'.$count_ref.' Users.</b></font></div>';
}

if(!empty($edit_profile_link)){
  echo '<div class="member_edit_link"><a href="'.$edit_profile_link.'">Edit Details</a></div>';
}

echo '<div style="clear: both; padding-bottom: 10px;"></div>';

$brands_pod = new Pod('brand');
$brands_pod->page = 1;
$brands_pod->search = 1;
$brands_pod->findRecords('id DESC', 10, "user.slug = '$slug'");
if($brands_pod->getTotalRows() > 0){
  echo "<strong>Favourite Brands</strong>";
  while ($brands_pod->fetchRecord()){
  $brand_name = $brands_pod->get_field('name');
  
  $brand_logo = $brands_pod->get_field('logo');
  $small_image =  wp_get_attachment_image_src($brand_logo[0][ID], 'thumbnail', false);
  $brand_logo = $small_image[0];
  
  $brand_url =  $brands_pod->get_field('brandurl');
  echo '<div class="fblogo" style="height: 50px;"><a href="'.BUZZR_URL.'/brands/'.$brand_url.'">';
  if(!empty($brand_logo))
  {
  echo '<img src="'.$brand_logo.'" alt="'.$brand_name.'" /><br />';
  }
  echo ucwords($brand_name).'</a></div>';
  }
  echo '<div style="clear: both;"></div>';
}
/* Widget Content */
?>

<?php 
/* Widget Logic */
is_pod_page('member/*')
/* Widget Logic */
?>